package com.wen.yygh.hosp.controller.api;

import com.wen.yygh.common.result.Result;
import com.wen.yygh.hosp.service.DepartmentService;
import com.wen.yygh.hosp.service.HospitalService;
import com.wen.yygh.hosp.service.HospitalSetService;
import com.wen.yygh.hosp.service.ScheduleService;
import com.wen.yygh.model.hosp.Hospital;
import com.wen.yygh.model.hosp.Schedule;
import com.wen.yygh.vo.hosp.DepartmentVo;
import com.wen.yygh.vo.hosp.HospitalQueryVo;
import com.wen.yygh.vo.hosp.ScheduleOrderVo;
import com.wen.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
@Slf4j
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("/findHospList/{pageNum}/{pageSize}")
    public Result findHospList(@PathVariable("pageNum") Integer pageNum,
                               @PathVariable("pageSize") Integer pageSize,
                               HospitalQueryVo hospitalQueryVo) {
        log.info("hospitalQueryVo=>" + hospitalQueryVo);
        Page<Hospital> result = hospitalService.findHospPageByHospitalQueryVo(pageNum, pageSize, hospitalQueryVo);
        return Result.ok(result);
    }

    @ApiOperation("根据医院名称查询")
    @GetMapping("/findHospByHosName/{hosname}")
    public Result findHospByHosName(@PathVariable("hosname") String hosname) {
        List<Hospital> hospitalList = hospitalService.findHospByHospName(hosname);
        return Result.ok(hospitalList);
    }

    @ApiOperation("根据医院编号获取科室列表")
    @GetMapping("getDepartment/{hoscode}")
    public Result getDepartmentByHoscode(@PathVariable("hoscode") String hoscode) {
        List<DepartmentVo> list = departmentService.getDepartmentListByHoscode(hoscode);
        return Result.ok(list);
    }

    @ApiOperation("根据医院编号获取医院详情")
    @GetMapping("getParticulars/{hoscode}")
    public Result getParticularsByHoscode(@PathVariable("hoscode") String hoscode) {
        Map<String, Object> map = hospitalService.getParticularsByHoscode(hoscode);
        return Result.ok(map);
    }

    @ApiOperation("获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRole/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@ApiParam(name = "page", value = "当前页码", required = true)
                                     @PathVariable Integer page,
                                     @ApiParam(name = "limit", value = "每页记录数", required = true)
                                     @PathVariable Integer limit,
                                     @ApiParam(name = "hoscode", value = "医院code", required = true)
                                     @PathVariable("hoscode") String hoscode,
                                     @ApiParam(name = "depcode", value = "科室code", required = true)
                                     @PathVariable String depcode) {
        log.info("hoscode=>" + hoscode);
        return Result.ok(scheduleService.getBookingScheduleRole(page, limit, hoscode, depcode));

    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    @ApiOperation("获取排版详情")
    @GetMapping("auth/getSchedule/{scheduleId}")
    public Result getScheduleById(@PathVariable("scheduleId") String scheduleId) {
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        return Result.ok(schedule);

    }
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }

}
